import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

const routes = [
  {
    path: '/home',
    name: 'home',
    component: () => import('@/views/Home.vue'),
    meta: { keepAlive: true }
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login.vue'),
    meta: { keepAlive: true }
  },
  {
    path: '/dorm',
    name: 'dorm',
    component: () => import('@/views/dormitory.vue'),
  },
  {
    path: '/info',
    name: 'info',
    component: () => import('@/views/user.vue'),
  },
  {
    path: '/followUs',
    name: 'followUs',
    component: () => import('@/views/followUs.vue'),
  },
  {
    path: '/record',
    name: 'record',
    component: () => import('@/views/payRecord.vue'),
    meta: { keepAlive: true }
  },
  {
    path: '/bill',
    name: 'bill',
    component: () => import('@/views/bill.vue'),
  },
  {
    path: '/fee',
    name: 'fee',
    component: () => import('@/views/lateFee.vue'),
  },
  {
    path: '/agree',
    name: 'agree',
    component: () => import('@/views/agreement.vue'),
  },
  {
    path: '/bond',
    name: 'bond',
    component: () => import('@/views/bond.vue'),
  },
  {
    path: '/clause',
    name: 'clause',
    component: () => import('@/views/clause.vue'),
  },
  {
    path: "/contract",
    name: "contract",
    component: () => import("@/views/customer/contract"),
  },
  {
    path: "/scan",
    name: "scan",
    component: () => import("@/views/customer/scan"),
  },
  //默认显示路由
  {
    path: "",
    redirect: "/home"
  }

]


const router = new VueRouter({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes,
  scrollBehavior(to, form, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else if (to.hash) {
      return {
        selector: to.hash
      };
    } else {
      return { x: 0, y: 0 };
    }
  }
})


router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})


export default router
